﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SynoManager.GUI;

namespace SynoManager.DownloadStation.Search
{
    [ServiceDependency(typeof(DownloadStationService))]
    public class SearchGuiPlugin : IGuiPlugin
    {
        private SynoDevice device;
        private IHost host;
        private SearchGuiTab tab;
        internal DownloadStationService service;
        private SearchManager manager = new SearchManager();

        private bool tabActive;
        public bool TabActive
        {
            set
            {
                tabActive = value;
                updateToolStrip();
            }
            get
            {
                return tabActive;
            }
        }

        public void Initialize(SynoDevice device)
        {
            this.device = device;
            service = device.FindService<DownloadStationService>();
            Debug.Assert(service != null, "DownloadStationService could not be found");
        }


        public void PopulatePreferencesForm(TreeViewEx treeView)
        {
        }

        public Control MainControl
        {
            get
            {
                return Tab;
            }
        }

        public SearchGuiTab Tab
        {
            get
            {
                if (tab == null)
                {
                    tab = new SearchGuiTab(this);
                    updateToolStrip();
                }
                return tab;
            }
        }

        internal IHost Host
        {
            get { return host; }
        }

        public SearchManager Manager
        {
            get { return manager; }
        }

        internal void updateToolStrip()
        {
        }

        public void InitializeHost(IHost host)
        {
            this.host = host;

            // Menu
            //var menu = (ToolStripDropDownItem)host.Menu.Items.Add("&Search");

            // Toolstrip
            //ToolStrip strip = new ToolStrip();
            //strip.Location = new Point(3, 24);

            
        }

        public int TabPriority
        {
            get { return 200; }
        }

        #region IGuiPlugin Members


        public void OnConnectionStateChange(bool isConnected, bool wasConnected)
        {
            
        }

        #endregion
    }
}
